public class SimpleTaskWorkManager
extends java.lang.Object
javax.resource.spi.work.WorkManager
implementation that
delegates to a Spring TaskExecutor
.
Provides simple task execution including start timeouts, but without support
for a JCA ExecutionContext (i.e. without support for imported transactions).
Uses a SyncTaskExecutor
for doWork(Work)
calls and a SimpleAsyncTaskExecutor
for startWork(Work)
and scheduleWork(Work)
calls, by default.
These default task executors can be overridden through configuration.
NOTE: This WorkManager does not provide thread pooling by default!
Specify a ThreadPoolTaskExecutor
(or any other thread-pooling TaskExecutor) as "asyncTaskExecutor" in order to
achieve actual thread pooling.
This WorkManager automatically detects a specified
AsyncTaskExecutor
implementation
and uses its extended timeout functionality where appropriate.
JCA WorkListeners are fully supported in any case.
setSyncTaskExecutor(org.springframework.core.task.TaskExecutor)
,
setAsyncTaskExecutor(org.springframework.core.task.AsyncTaskExecutor)
Modifier and Type | Class and Description |
---|---|
private static class |
SimpleTaskWorkManager.DelegatingWorkAdapter
Work adapter that supports start timeouts and WorkListener callbacks
for a given Work that it delegates to.
|
Modifier and Type | Field and Description |
---|---|
private AsyncTaskExecutor |
asyncTaskExecutor |
private TaskExecutor |
syncTaskExecutor |
Constructor and Description |
---|
SimpleTaskWorkManager() |
Modifier and Type | Method and Description |
---|---|
void |
doWork(Work work) |
void |
doWork(Work work,
long startTimeout,
ExecutionContext executionContext,
WorkListener workListener) |
protected long |
executeWork(TaskExecutor taskExecutor,
Work work,
long startTimeout,
boolean blockUntilStarted,
ExecutionContext executionContext,
WorkListener workListener)
Execute the given Work on the specified TaskExecutor.
|
void |
scheduleWork(Work work) |
void |
scheduleWork(Work work,
long startTimeout,
ExecutionContext executionContext,
WorkListener workListener) |
void |
setAsyncTaskExecutor(AsyncTaskExecutor asyncTaskExecutor)
Specify the TaskExecutor to use for asynchronous work execution
(i.e.
|
void |
setSyncTaskExecutor(TaskExecutor syncTaskExecutor)
Specify the TaskExecutor to use for synchronous work execution
(i.e.
|
long |
startWork(Work work) |
long |
startWork(Work work,
long startTimeout,
ExecutionContext executionContext,
WorkListener workListener) |
@Nullable private TaskExecutor syncTaskExecutor
@Nullable private AsyncTaskExecutor asyncTaskExecutor
public void setSyncTaskExecutor(TaskExecutor syncTaskExecutor)
doWork(Work)
calls).
Default is a SyncTaskExecutor
.
public void setAsyncTaskExecutor(AsyncTaskExecutor asyncTaskExecutor)
startWork(Work)
and scheduleWork(Work)
calls).
This will typically (but not necessarily) be an
AsyncTaskExecutor
implementation.
Default is a SimpleAsyncTaskExecutor
.
public void doWork(Work work) throws WorkException
WorkException
public void doWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener) throws WorkException
WorkException
public long startWork(Work work) throws WorkException
WorkException
public long startWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener) throws WorkException
WorkException
public void scheduleWork(Work work) throws WorkException
WorkException
public void scheduleWork(Work work, long startTimeout, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener) throws WorkException
WorkException
protected long executeWork(TaskExecutor taskExecutor, Work work, long startTimeout, boolean blockUntilStarted, @Nullable ExecutionContext executionContext, @Nullable WorkListener workListener) throws WorkException
taskExecutor
- the TaskExecutor to usework
- the Work to executestartTimeout
- the time duration within which the Work is supposed to startblockUntilStarted
- whether to block until the Work has startedexecutionContext
- the JCA ExecutionContext for the given WorkworkListener
- the WorkListener to clal for the given WorkWorkException
- if the TaskExecutor did not accept the Work